package net.xo68.destiny.starter.worker.handler;

import lombok.Data;
import lombok.ToString;

import java.util.Objects;

/**
 * 任务的脚本类型
 * @author wuxie
 * @version 2020-11-23
 */
@ToString
@Data
public class JobSourceCodeType {

    public static final JobSourceCodeType WINDOWS_CMD=new JobSourceCodeType("windows_cmd","cmd",false,".cmd");
    public static final JobSourceCodeType PYTHON=new JobSourceCodeType("python","python",true,".py");
    public static final JobSourceCodeType NODE_JS=new JobSourceCodeType("Nodejs","node",true,".js");
    public static final JobSourceCodeType PHP=new JobSourceCodeType("php","php",true,".php");
    public static final JobSourceCodeType SHELL=new JobSourceCodeType("shell","bash",true,".sh");
    public static final JobSourceCodeType POWER_SHELL=new JobSourceCodeType("powershell","powershell",true,".ps1");
    public static final JobSourceCodeType GOLANG=new JobSourceCodeType("golang","go run",true,".go");

    public static final JobSourceCodeType GROOVY=new JobSourceCodeType("groovy","",false,".groovy",false);

    /**
     * 语言类型
     */
    private String languageType;
    /**
     * 任务执行命令
     */
    private String cmd;
    /**
     * 是否需要输入源码脚本执行的命令
     */
    private boolean inputCmd;
    /**
     * 后缀
     */
    private String suffix;
    /**
     * 是否是脚本
     */
    private boolean script;

    public JobSourceCodeType() {
    }

    public JobSourceCodeType(String languageType, String cmd, String suffix) {
        this(languageType,cmd,true,suffix,true);
    }
    public JobSourceCodeType(String languageType, String cmd,boolean inputCmd, String suffix) {
        this(languageType,cmd,inputCmd,suffix,true);
    }

    public JobSourceCodeType(String languageType, String cmd,boolean inputCmd, String suffix, boolean script) {
        this.languageType = languageType;
        this.cmd = cmd;
        this.inputCmd=inputCmd;
        this.suffix = suffix;
        this.script = script;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        JobSourceCodeType that = (JobSourceCodeType) o;
        return inputCmd == that.inputCmd &&
                script == that.script &&
                languageType.equals(that.languageType) &&
                cmd.equals(that.cmd) &&
                suffix.equals(that.suffix);
    }

    @Override
    public int hashCode() {
        return Objects.hash(languageType, cmd, inputCmd, suffix, script);
    }
}
